<template>
  <a-modal
    :title="title"
    :width="1600"
    :visible="visible"
    @ok="handleOk"
    @cancel="handleCancel"
    :cancelText="$t('systemManagement.close')"
    wrapClassName="ant-modal-cust-warp"
    style="top:5%;height: 100%;overflow-y: hidden">
    <template slot="footer">
      <a-button key="back" @click="handleCancel">{{$t('inPrint.cancel')}}</a-button>
    </template>
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <!-- 搜索区域 -->
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item :label="$t('setailManagement.documentNo')" :labelCol="{span: 5}" :wrapperCol="{span: 18, offset: 1}">
              <a-input :placeholder="$t('inPrint.pleaseDocumentNumber')" v-model="queryParam.number"></a-input>
            </a-form-item>
          </a-col>
          <!-- <a-col :md="6" :sm="8">
            <a-form-item :label="$t('setailManagement.productInformation')" :labelCol="{span: 5}" :wrapperCol="{span: 18, offset: 1}">
              <a-input :placeholder="$t('inPrint.pleaseSpecificationModel')" v-model="queryParam.materialParam"></a-input>
            </a-form-item>
          </a-col> -->
          <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
            <a-col :md="6" :sm="24">
              <a-button type="primary" @click="searchQuery">{{$t('setailManagement.query')}}</a-button>
              <a-button style="margin-left: 8px" @click="searchReset">{{$t('setailManagement.reset')}}</a-button>
            </a-col>
          </span>
        </a-row>
      </a-form>
    </div>
    <!-- table区域-begin -->
    <a-table
      bordered
      ref="table"
      size="middle"
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      @change="handleTableChange">
      <span slot="numberCustomRender" slot-scope="text, record">
        <a @click="myHandleDetail(record,record.type)">{{record.billNo}}</a>
      </span>
    </a-table>
    <!-- table区域-end -->
    <!-- 表单区域 -->
    <bill-detail ref="modalDetail"></bill-detail>
    <financial-detail ref="FinancialDetail"></financial-detail>
  </a-modal>
</template>

<script>
  import BillDetail from '../../bill/dialog/BillDetail'
  import FinancialDetail from '@views/financial/dialog/FinancialDetail'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { findBillDetailByNumber, findFinancialDetailByNumber } from '@/api/api'
  import { JEditableTableMixin } from '@/mixins/JEditableTableMixin'
  import { FinancialListMixin } from '@views/financial/mixins/FinancialListMixin'
  import Vue from 'vue'
import JEditableTableVue from '../../../components/jeecg/JEditableTable.vue'

  export default {
    name: 'DebtAccountList',
    mixins:[JeecgListMixin, JEditableTableMixin],
    components: {
      BillDetail,
      FinancialDetail
    },
    data () {
      return {
        title:this.$t('setailManagement.operation'),
        visible: false,
        disableMixinCreated: true,
        queryParam: {
          organId: "",
          materialParam: "",
          number: "",
          type: "",
          subType: "",
          roleType: Vue.ls.get('roleType'),
          status: ""
        },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 8 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        // 表头
        columns: [
        ],
        url: {
          list: "/accountHead/getAccountHeadByOrganId"
        }
      }
    },
    computed: {
      getType: function () {
        return 'checkbox';
      }
    },
    created() {
    },
    methods: {
      show(organId, type, subType, organType, status, beginTime, endTime, type1, subType1) {
        this.queryParam.organId = organId
        this.queryParam.type = type
        this.queryParam.subType = subType
        this.queryParam.status = status
        this.queryParam.beginTime = beginTime
        this.queryParam.endTime = endTime
        this.queryParam.type1 = type1
        this.queryParam.subType1 = subType1
        // this.queryParam.supplier = supplier
        this.columns[2].title = organType
        // if(type === '入库') {
        //   this.columns[7].title = this.$t('inPrint.arrearsReceived')
        //   this.columns[8].title = this.$t('inPrint.debtCollected')
        // } else if(type === '出库') {
        //   this.columns[7].title = this.$t('inPrint.arrearsReceived')
        //   this.columns[8].title = this.$t('inPrint.debtCollected')
        // }
        this.model = Object.assign({}, {});
        this.visible = true;
        this.ipagination.pageSize = 101
        this.ipagination.pageSizeOptions = ['101', '201', '301']
        this.loadData(1)
      },
      myHandleDetail(record, type) {
        const types = ['支出','付款','付预付款','收入','收款','收预付款','直发收款','直发预收款','直发预付','支票核销','预收款单','预付款单']
        if (types.includes(type)) {
            findFinancialDetailByNumber({ billNo: record.billNo }).then((res) => {
              if (res && res.code === 200) {
                let type = res.data.type
                this.$refs.FinancialDetail.show(res.data,type)
                this.$refs.FinancialDetail.setTitle(type)
              }
            })
        } else {
          // this.handleDetail(record, type)
          findBillDetailByNumber({ number: record.billNo }).then((res) => {
            if (res && res.code === 200) {
              let type = res.data.subType
              this.handleDetail(res.data, type)
            }
          })
        }
      },
      // myHandleDetail(record) {
      //   findFinancialDetailByNumber({ billNo: record.billNo }).then((res) => {
      //     if (res && res.code === 200) {
      //       let type = res.data.type
      //       this.handleDetail(res.data, type)
      //     }
      //   })
      // },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleCancel () {
        this.close()
      },
      onDateOk(value) {
        console.log(value);
      },
      searchReset() {
        this.queryParam = {
          organId: this.queryParam.organId,
          type: this.queryParam.type,
          subType: this.queryParam.subType,
          beginTime: this.queryParam.beginTime,
          endTime: this.queryParam.endTime,
          roleType: Vue.ls.get('roleType'),
        }
        this.loadData(1);
      },
    }
  }
</script>

<style scoped>

</style>